package domain.DAO;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Example;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateTemplate;

import util.HibernateUtil;
import domain.Contact;
import domain.Entreprise;
import domain.interfaces.IDAOContact;

public class DAOContact extends DAOCrud<Contact> implements IDAOContact {

	public DAOContact() {
		super(Contact.class);
	}

	@Override
	public Contact find(long id) {
		DetachedCriteria query = DetachedCriteria.forClass(Contact.class)
				.add(Restrictions.idEq(id))
				.setFetchMode("add", FetchMode.JOIN)
				.setFetchMode("books", FetchMode.JOIN)
				.setFetchMode("phones", FetchMode.JOIN);
		return (Contact) hibernateTemplate.findByCriteria(query).get(0);
	}
	
	@Override
	public void delete(Contact entity) {
		hibernateTemplate.delete("domain.Contact", entity);
	}
}
